/*
 * create:2015年11月22日 上午10:42:58
 * author:wangds  
 */
package com.cxkj.shop.biz;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.wangds.comp.business.http.AbstractHttpInteractionBusiness;
import net.wangds.comp.json.JsonUtil;

import org.apache.log4j.Logger;

/**
 * 验证配置是否正确.
 * 
 * @author wangds
 *
 */
public class DemoBusiness extends AbstractHttpInteractionBusiness<Map<String, Object>, Map<String, Object>> {

    /*
     * @see eastone.common.processor.Processor#process()
     * 
     * @author wangds 2015年5月10日 上午11:03:15.
     */
    @Override
    public void process() throws Exception {
        Logger.getRootLogger().info("com.cxkj.shop.biz.DemoBusiness.process() starting");
        //System.out.println("TestBiz.process() starting");
        
        Map<String, Object> in = this.getInput();
        
        System.out.println(JsonUtil.toJson("demo in:"+in));
        
        Map<String, Object> out = new HashMap<String, Object>();
        
        out.put("ip", getIpAddr(this.getHttpRequest()));
        
        this.setOutput(out);
        
        Logger.getRootLogger().info("com.cxkj.shop.biz.DemoBusiness.prcess() ending");
    }
    
    public static String getIpAddr(HttpServletRequest request) {
      String ip = request.getHeader("x-forwarded-for");
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
          ip = request.getHeader("Proxy-Client-IP");
      }
      if (ip == null || ip.length() == 0 || "unknow".equalsIgnoreCase(ip)) {
          ip = request.getHeader("WL-Proxy-Client-IP");
      }
      if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
          ip = request.getRemoteAddr();
      }
      return ip;
  }

}
